/***********************
 * Inquiry Summary Panel
 */
AIR2.Inquiry.Summary = function() {
    var formatQuestion = function(ques) {
        var str = "";
        if (!ques.ques_choices) {
            str = ques.ques_value;
        }
        else if (ques.ques_type == "M") {
            var defaultVal;
            var opts = [];
            var choices = Ext.decode(ques.ques_choices);
            Ext.each(choices, function(item,idx,arr) {
                if (item.isdefault) {
                    defaultVal = item.value;
                }
                opts.push(item.value);
            });
            Ext.each(opts, function(item,idx,arr) {
                str += '<input type="checkbox"/> ' + item + '<br />'; 
            });
            str = ques.ques_value + '<div class="air2-inq-ques-choices">'+str+'</div>';
        }
        else if (ques.ques_type == "S") {
            var defaultVal;
            var opts = [];
            var choices = Ext.decode(ques.ques_choices);
            Ext.each(choices, function(item,idx,arr) {
                if (item.isdefault) {
                    defaultVal = item.value;
                }       
                opts.push(item.value);
            });
            str = '<select>';
            Ext.each(opts, function(item,idx,arr) {
                str += '<option' +(defaultVal==item?'selected="selected"':'')+ '> ' + item + '</option>'; 
            });     
            str += '</select>';
            str = ques.ques_value + '<div class="air2-inq-ques-choices">'+str+'</div>';
        }

        return str;
    }
    return new AIR2.UI.Panel({
        colspan: 2,
        rowspan: 2,
        title: 'Summary',
        iconCls: 'air2-inquiry-summary-icon',
        storeData: AIR2.Inquiry.QUESDATA,
        url: AIR2.Inquiry.INQURL,
        tpl: new Ext.XTemplate(
            '<div class="air2-inquiry-summary">' +
             '<h3>{[AIR2.Inquiry.INQDATA.radix.inq_ext_title]}</h3>' +
              '<div>Project: {[AIR2.Format.projectName(AIR2.Inquiry.INQDATA.radix.ProjectInquiry[0].Project, true)]}</div>',
              '<div>Published: {[AIR2.Format.date(AIR2.Inquiry.INQDATA.radix.inq_publish_dtim||AIR2.Inquiry.INQDATA.radix.inq_cre_dtim)]}</div>' +
              '<div>Author: {[AIR2.Format.userName(AIR2.Inquiry.INQDATA.radix.CreUser, true)]}</div>' +
              '<div class="air2-project-summary">' +
               '<ul class="air2-project-sharing"><li>Shared?</li>{[AIR2.Format.shared(AIR2.Inquiry.INQDATA.radix.ProjectInquiry[0].Project.prj_shared_flag)]}</ul>' +
               '<ul class="air2-project-status"><li>Status</li>{[AIR2.Format.status(AIR2.Inquiry.INQDATA.radix.inq_status)]}</ul>' +
              '</div>' +
            '</div>' +
            '<table class="air2-inq-questions">' +
             '<tpl for=".">' +
              '<tr>' +
              '<th class="air2-inq-ques-seq">{ques_dis_seq}.</th>' +
              '<td class="air2-inq-question">{[this.formatQuestion(values)]}</td>' +
              '</tr>' +
             '</tpl>' +
            '</table>',
            {
                compiled: true, 
                disableFormats: true,
                formatQuestion: formatQuestion
            }
        )       

    });
}
